package com.bl.student.common.enums.pay;

import com.bl.student.common.utils.ReflectionUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by yujingyi on 2017/11/8.
 */
@Data
@Builder
public class WechatPayPayInfoVo extends AbstractVo {

    private String outTradeNo;

    private PayInfo payInfo;

    @Data
    @Builder
    static public class PayInfo {
        private String appid;

        private String partnerid;

        private String packageValue;

        private String noncestr;

        private String sign;

        private String prepayid;

        private String timestamp;

        private String signType;

        private String key;

        @JsonIgnore
        public Map<String, Object> getSortedParams() {

            Map<String, Object> sortMap = new TreeMap<String, Object>(
                    new Comparator<String>() {
                        @Override
                        public int compare(String str1, String str2) {

                            return str1.compareTo(str2);
                        }
                    });
            Map<String, Object> paramMap = ReflectionUtil.objectToMap(this, false, false);
            sortMap.putAll(paramMap);

            return sortMap;
        }
    }


}
